package com.csw.android.ffmpegtest.ui.section2

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.csw.android.ffmpegtest.model.FileModel
import java.io.File

open class Section201ViewModel : ViewModel() {

    val wavFileList: MutableLiveData<MutableList<File>?> = MutableLiveData()
    val filePlayState: MutableLiveData<HashMap<String, Int>> = MutableLiveData(HashMap())
    open fun refreshFileList() {
        FileModel.getSection201WavFileList()
            .subscribe(
                {
                    wavFileList.postValue(it)
                },
                {
                    wavFileList.postValue(null)
                }
            )
    }

    fun updatePlayState(filePath: String, progress: Int) {
        if (progress < 0) {
            filePlayState.value?.remove(filePath)
        } else {
            filePlayState.value?.put(filePath, progress)
        }
        filePlayState.postValue(filePlayState.value)
    }

}